<template>
  <div>
    <!--    结案前需要展示的东西-->
    <el-card class="box-card">

      <el-form class="form-label" ref="form" :model="form" label-width="150px">
        <div style="margin-top: 2px">
          <div class="shijianyangshi">事件摘要</div>
          <div class="xian"></div>
          <div style="margin-top: 20px">
            <el-form-item label="事件描述和事情经过" prop="discussionDepartmentDate">
              <div style="color: #4d89dd; font-size: 14px ">
                {{ form.situationEdescriptionProcess }}
              </div>
            </el-form-item>
            <div class="line"/>

            <el-form-item label="填报人" prop="discussionSite">
              <div style="color: #4d89dd; font-size: 14px ">
                {{ form.reportFiller }}
              </div>
            </el-form-item>
            <div class="line"/>
            <el-form-item label="发生时间" prop="discussionPanelist">
              <div style="color: #4d89dd; font-size: 14px">
                {{ form.occurrenceTime }}
              </div>
            </el-form-item>
            <el-form-item label="事件状态" prop="discussionPanelist">
              <div style="color: #4d89dd; font-size: 14px">
                <dict-tag style="color: #4d89dd" :options="dict.type.he_report_event_state"
                          :value="form.reportEventState"/>
              </div>
            </el-form-item>
            <el-form-item label="事件严重程度" prop="discussionPanelist">
              <!--          <div style="color: #4d89dd"  >-->
              <!--            {{form.resultsEventSeverity}}-->
              <!--          </div>-->
              <div class="block" style="font-size: 14px">
                <!--            A级:客观环境或条件可能引发不良事件(不良事件隐患)-->
                <el-tag class="el-tag" v-if="form.resultsEventSeverity==='01'" type="success">
                  <dict-tag :options="dict.type.he_event_severity" :value="form.resultsEventSeverity"/>
                </el-tag>
                <el-tag class="el-tag"
                        v-if="form.resultsEventSeverity==='02'||form.resultsEventSeverity==='03'||form.resultsEventSeverity==='04'">
                  <dict-tag :options="dict.type.he_event_severity" :value="form.resultsEventSeverity"/>
                </el-tag>
                <el-tag style=" background-color:#FFF68F;border-color:#fff1cc;" class="el-tag"
                        v-if="form.resultsEventSeverity==='05'||form.resultsEventSeverity==='06'||form.resultsEventSeverity==='07'||form.resultsEventSeverity==='08'"
                        type="warning">
                  <dict-tag style="color:#CD9B1D;" :options="dict.type.he_event_severity"
                            :value="form.resultsEventSeverity"/>
                </el-tag>
                <el-tag class="el-tag" v-if="form.resultsEventSeverity==='09'" type="danger">
                  <dict-tag :options="dict.type.he_event_severity" :value="form.resultsEventSeverity"/>
                </el-tag>

              </div>
            </el-form-item>
            <el-form-item label="事件分级" prop="discussionPanelist">
              <div class="block" style="font-size: 14px">
                <!--            IV级事件:错误未发生(错误隐患)(包括损害程度A级)-->
                <el-tag class="el-tag" v-if="form.resultsEventClassification==='04'" type="success">
                  <dict-tag :options="dict.type.he_event_classification" :value="form.resultsEventClassification"/>
                </el-tag>
                <!--            Ⅲ级事件:发生错误，但未造成患者伤害(包括损害程度B、C、D级)-->
                <el-tag class="el-tag" v-if="form.resultsEventClassification==='03'">
                  <dict-tag :options="dict.type.he_event_classification" :value="form.resultsEventClassification"/>
                </el-tag>
                <!--            Ⅱ级事件:发生错误，且造成患者伤害(包括损害程度E、F、G、H级)-->
                <el-tag style=" background-color:#FFF68F;border-color:#fff1cc;" class="el-tag"
                        v-if="form.resultsEventClassification==='02'" type="warning">
                  <dict-tag style="color:#CD9B1D;" :options="dict.type.he_event_classification"
                            :value="form.resultsEventClassification"/>
                </el-tag>
                <!--            I级事件:发生错误，造成患者死亡(包括损害程度I级)-->
                <el-tag class="el-tag" v-if="form.resultsEventClassification==='01'" type="danger">
                  <dict-tag :options="dict.type.he_event_classification" :value="form.resultsEventClassification"/>
                </el-tag>
              </div>
            </el-form-item>
            <el-form-item label="伤害严重度" prop="discussionPanelist">
              <div class="block" style="font-size: 14px">
                <dict-tag style="color: #4d89dd" :options="dict.type.he_severity_of_injury"
                          :value="form.resultsSeverityInjury"/>
              </div>
            </el-form-item>
          </div>
          <!--    意见部分-->
          <div style="margin-top: 2px">
            <div class="shijianyangshi">主任意见</div>
            <div class="xian"></div>
            <div style="margin-top: 20px">
              <el-form-item label="是否同意该处理结果" prop="reviewEventType">
                <el-tag v-if="this.form.note8=='01'" type="success">同意</el-tag>
                <el-tag v-else-if="this.form.note8=='02'" type="danger">不同意</el-tag>
                <el-tag v-else type="info">未填写</el-tag>
              </el-form-item>
            </div>
            <div class="line"/>
            <el-form-item  label="原因" prop="handlingStatus">
              <el-input
                  :readonly="true"
                  type="textarea"
                  :rows="10"
                  resize="none"
                  placeholder="请输入原因"
                  maxlength="500"
                  show-word-limit
                  v-model="form.note9">
              </el-input>
            </el-form-item>
          </div>
          <!--    结案部分-->
          <div style="margin-top: 2px">
            <div class="shijianyangshi">事件结案</div>
            <div class="xian"></div>
            <div style="margin-top: 20px">
              <el-form-item v-if="this.form.reportEventState=='03'" label="事件类型判定" prop="reviewEventType">
                <el-select v-model="form.reviewEventType" placeholder="请选择">
                  <el-option
                      v-for="dict in dict.type.he_review_event_type"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
            <div class="line"/>
            <el-form-item v-if="this.form.reportEventState=='03'" label="事件处理状态" prop="handlingStatus">
              <el-select v-model="form.handlingStatus" placeholder="请选择">
                <el-option
                    v-for="dict in dict.type.he_handling_status"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value">
                </el-option>
              </el-select>
            </el-form-item>
            <!--        事件改派-->
            <el-form-item v-if="form.handlingStatus=='01'" label="事件改派部门" prop="handlingStatus">
              <el-select filterable v-model="form.reviewDepartment" placeholder="请选择">
                <el-option
                    v-for="dict in dict.type.he_department_name"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <!--          如果事件是已处理才可以结案-->
              <el-popover
                  v-if="form.handlingStatus=='02'"
                  placement="bottom"
                  title="注意"
                  width="200"
                  trigger="hover"
                  content="在结案前请仔细核对分析报告和处理建议的完善情况">
                <el-button v-if="this.form.reportEventState=='03'" slot="reference" @click="shangbao">结 案</el-button>
              </el-popover>
              <el-button
                  v-if="form.handlingStatus=='01'"
                  type="primary" @click.prevent.native="gai" plain>改 派
              </el-button>
            </el-form-item>
          </div>
        </div>
      </el-form>

      <!--    结案后需要展示的东西-->

      <el-form v-if="this.form.reportEventState=='04'" class="form-label" ref="form" :model="form" label-width="150px">
        <div style="margin-top: 20px">
          <el-form-item label="事件类型判定" prop="reviewEventType">
            <el-select v-model="form.reviewEventType" placeholder="请选择" :disabled="true">
              <el-option
                  v-for="dict in dict.type.he_review_event_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value">
              </el-option>
            </el-select>
          </el-form-item>
          <div class="line"/>

          <el-form-item label="事件处理状态" prop="handlingStatus">
            <el-select v-model="form.handlingStatus" placeholder="请选择" :disabled="true">
              <el-option
                  v-for="dict in dict.type.he_handling_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value">
              </el-option>
            </el-select>
          </el-form-item>
        </div>
      </el-form>

    </el-card>
  </div>
</template>

<script>
import {getReport, jieanReport, gaipaiReport} from "@/api/module/shao/shijian/report";

export default {
  name: "Report",
  inject: ['reload'],
  dicts: ['he_handling_status', 'he_department_name', 'he_review_event_type', 'he_severity_of_injury', 'he_event_severity', 'he_education', 'he_patient_gender', 'he_party_post', 'he_report_event_state', 'he_report_event_type', 'he_patient_age_grades', 'he_event_severity', 'he_review_status', 'he_report_status', 'he_position', 'he_event_classification', 'he_review_event_type', 'he_possibility_of_dispute', 'he_patient_involved', 'he_analyze_reports', 'he_fallback_status', 'he_occurrence_time_period', 'he_event_determinatione', 'he_situation_measures_event', 'he_patient_education_level', 'he_diagnosis_category', 'he_years_of_experience', 'he_severity_of_injury', 'he_reporting_method', 'he_patient_nursing_level', 'he_date_type', 'he_invalidation_status', 'he_patient_ethnic_group', 'he_category', 'he_handling_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 事件上报信息表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    //登录用户是这个部门的this.$store.state.user.deptid
    getReport(this.$route.query.id).then(response => {
      this.form = response.data;
    });
  },
  methods: {
    // 改派事件
    gai() {
      //健壮性判断不能改派到本科室逻辑漏洞
      if (this.form.reviewDepartment == this.$store.state.user.deptid) {
        this.$modal.msgWarning("改派的部门不能是自身当前所在的部门");
      } else {
        //走改派接口
        gaipaiReport(this.form).then(response => {
          this.$modal.msgSuccess("改派成功");
          //跳转回处理事件页面
          //this.$router.push({path: "/hosipitalevent/chulishijian"});
          const obj = {path: "/hosipitalevent/chulishijian?value1=true&type=" + this.form.reviewEventType + "&state=01"};
          this.$tab.closeOpenPage(obj);
        });
      }
    },
    //结案方法点击事件
    shangbao() {
      this.$confirm('确定结案该事件?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        //改变reportEventState字段的状态04为结案
        this.form.handlingStatus = '02'
        this.form.reportEventState = '04'
        this.form.reviewDepartment = null
        jieanReport(this.form).then(response => {
          const obj = {path: "/hosipitalevent/chulishijian?value1=true&type=" + this.form.reviewEventType + "&state=01"};
          this.$tab.closeOpenPage(obj);
          //this.$router.push({path: "/hosipitalevent/chulishijian"});
        });
        this.$message({
          type: 'success',
          message: '结案成功!',
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消结案该事件'
        });
      });

    },

  }
};
</script>
<style lang="scss" scoped>
//@import "src/views/module/shao/blackFont";
.shijianyangshi {
  font-weight: bold;
  font-size: 20px;
  color: #000000;
  text-align: left;
}

.xian {
  border-bottom: 1px solid #ebebeb;
  margin-top: 0.5%;
}

.el-tag {
  font-size: 14px;
}


.form-label {
  ::v-deep .el-form-item__label {
    font-size: 15px;
    font-weight: bold;
  }

}


</style>
